using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

/// <summary>
/// Summary description for ControlBasic
/// </summary>
public class ControlBasic
{
    public ControlBasic()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    // basic abstract functions
    public void SetControlList(DataView dview, CheckBoxList control, string strValue)
    {
        control.Items.Clear();

        control.DataSource = dview;
        control.DataTextField = "ctl_text";
        control.DataValueField = "ctl_value";
        control.DataBind();

        SetControlSelected(control, strValue);
    }


    
    public decimal GetQuoteFromDayPackage(DropDownList control)
    {
        decimal amt = 0;

        string strText = control.SelectedItem.Text;

        int sp = strText.IndexOf("$");
        sp = sp + 1;
        int ep = strText.IndexOf(")");
        strText = strText.Substring(sp, ep - sp);

        amt = Convert.ToDecimal(strText);

        return amt;
    }

    public void SetControlList(DataView dview, DropDownList control, string strValue)
    {
        control.Items.Clear();

        control.DataSource = dview;
        control.DataTextField = "ctl_text";
        control.DataValueField = "ctl_value";
        control.DataBind();


        control.Visible = control.Items.Count==0?false:true;
        SetControlSelected(control, strValue);
    }

    public void SetControlList(DataView dview, RadioButtonList control, string strValue)
    {
        control.Items.Clear();

        control.DataSource = dview;
        control.DataTextField = "ctl_text";
        control.DataValueField = "ctl_value";
        control.DataBind();

        SetControlSelected(control, strValue);
    }


    public void SetControlSelected(DropDownList control, string strValue)
    {
        int isel;
        if (control.Items.Count == 0)
            return;
        isel = control.Items.IndexOf(control.Items.FindByValue(strValue));
        if (isel < 0)
            isel = 0;
        control.SelectedIndex = isel;
    }

    public void SetControlSelected(RadioButtonList control, string strValue)
    {
        int isel;
        isel = control.Items.IndexOf(control.Items.FindByValue(strValue));
        if (isel < 0)
            isel = 0;
        control.SelectedIndex = isel;
    }

    public void SetControlSelected(CheckBoxList control, string strValue)
    {
        int isel;
        isel = control.Items.IndexOf(control.Items.FindByValue(strValue));
        if (isel < 0)
            isel = 0;
        control.SelectedIndex = isel;
    }


    public String GetCategoryValue_Parent(DataSet ds_Cate, int icategory)
    {     

        // gain default value
        DataRow[] rows = ds_Cate.Tables[0].Select(" ct_id = " + icategory);
        string strValue = icategory.ToString();
        string strParentValue = rows[0]["parent_id"].ToString();

        if (strParentValue == null || strParentValue == "")
            strParentValue = strValue;
        //

        return strParentValue;
    }

    public void SetStyleList(DataSet ds_style, RadioButtonList control, String col)
    {
        DataView dv = ds_style.Tables[0].DefaultView;
        dv.RowFilter = "unit =" + col;

        SetControlList(dv, control, "");
    }
    public String GetStyleValue(DataSet ds_style, String selectedValue)
    {
        DataRow[] rows = ds_style.Tables[0].Select(String.Format(" ctl_value = '{0:s}'", selectedValue));
        if (rows.Length > 0)
            return rows[0]["name"].ToString();
        return "";
    }
    public String GetStyleWidth(String selectedValue)
    {
        string[] strValue = selectedValue.Split(',');
        return strValue[0];
    }
    public String GetStyleHeight(String selectedValue)
    {
        string[] strValue = selectedValue.Split(',');
        return strValue[1];
    }
    public string GetStyleXSLName(RadioButtonList control)
    {
        string[] strValue = control.SelectedValue.Split(',');
        return strValue[2];
    }
    public String GetStyleXSLUrl(DataSet ds_style, String selectedValue)
    {
        DataRow[] rows = ds_style.Tables[0].Select(String.Format(" ctl_value = '{0:s}'", selectedValue));
        if (rows.Length > 0)
            return rows[0]["xslurl"].ToString();
        return "";
    }

    public String GetStyleXMLUrl(DataSet ds_style, String selectedValue)
    {
        DataRow[] rows = ds_style.Tables[0].Select(String.Format(" ctl_value = '{0:s}'", selectedValue));
        if (rows.Length > 0)
            return rows[0]["xmlurl"].ToString();
        return "";
    }

    public String GetStyleIMGUrl(DataSet ds_style, String selectedValue)
    {
        DataRow[] rows = ds_style.Tables[0].Select(String.Format(" ctl_value = '{0:s}'", selectedValue));
        if (rows.Length > 0)
            return rows[0]["jpgurl"].ToString();
        return "";
    }

    public String GetStyleRootUrl(DataSet ds_style, String selectedValue)
    {
        DataRow[] rows = ds_style.Tables[0].Select(String.Format(" ctl_value = '{0:s}'", selectedValue));
        if (rows.Length > 0)
            return rows[0]["rooturl"].ToString();
        return "";
    }

    public double GetValueText(string strValue)
    {
        if (strValue == null || strValue == "")
            strValue = "0";

        return Convert.ToDouble(strValue);
    }

 


}
